`include "defines.svh"
`include "CP0Defines.svh"
module control (
    input [31:0]ID_Instr,            //指令
    input ExceptionType ID_ExceptionType, 

    output logic [1:0]ID_EXTOp,       //立即数扩展选择
                                    //2'b10 lui->立即数加载至高位
                                    //2'b00 andi xori ori 立即数零扩展
                                    //2'b01 其他指令 立即数符号扩展
    output logic [4:0]ID_ALUOp,       //ALU选择
    output logic ID_DMWr,             //数据存储器写使能信号 1有效
    output logic ID_ALU_DataA_Sig,   
    output logic ID_ALU_DataB_Sig,    //ALU两个操作数选择
    output logic [2:0]ID_Reg_Writed,  //写入寄存器选择
                                    //0->0 can't write  
                                    //1->$31 
                                    //2->rt 
                                    //3->rd 
                                    //4->HI
                                    //5->LO
                                    //6->HI&LO
                                    //7->CP0

    output logic [2:0]ID_DMOp,        //数据存储器写入选择
                                      //选择写入的类型
                                      //一个字节,半字,一个字
                                      //有无符号
    output logic ID_MemToRegWr,       //load写有效 1有效
    output logic ID_Immjump,          //是否立即跳转 1有效
    output logic ID_IsBranch,         //是否分支 1有效
    output logic [1:0]ID_Data_To_Reg_Sel,      //选择写入寄存器的值
                                            //2'b00 ALU结果
                                            //2'b01 数据存储器读取结果(load指令)
                                            //2'b10 PC+8
                                            //2'11 CP0
    output ExceptionType ID_ExceptionTypeEnd,   //更新之后异常类型，可能会产生syscall，break，ReservedInstr例外
    output logic ID_CP0Wr,                    //CP0写使能
    output logic ID_DMRd
);
    logic [5:0]opcode;
    logic [5:0]funct;
    logic [4:0]rs;
    logic [4:0]rt;
    logic [4:0]rd;
    logic [4:0]shamt;

    assign opcode = ID_Instr[31:26];
    assign funct = ID_Instr[5:0];
    assign rs = ID_Instr[25:21];
    assign rt = ID_Instr[20:16];
    assign rd = ID_Instr[15:11];
    assign shamt = ID_Instr[10:6];

    always_comb begin
        unique case(opcode)
        `R_type:begin
            unique case(funct)
            `add:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `addu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = `ALU_addu;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `sub:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;         
                ID_ALUOp = `ALU_sub;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `subu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = `ALU_subu;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `slt:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = `ALU_slt;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `sltu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = `ALU_sltu;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `div:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = `ALU_div;;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b110;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `divu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;    
                ID_ALUOp = `ALU_divu;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b110;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `mult:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = `ALU_mul;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b110;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `multu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;         
                ID_ALUOp = `ALU_mulu;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b110;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `and_:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_and;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `nor_:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_nor;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `or_:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_or;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `xor_:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_xor;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `sll:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_sll;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `srl:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_srl;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `sra:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_sra;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `sllv:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_sll;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `srlv:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_srl;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `srav:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_sra;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `jalr:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_A;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b001;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b1;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b10;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `jr:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                 
                ID_ALUOp = `ALU_A;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b1;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `mfhi:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `mflo:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b011;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `mthi:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_A;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b100;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `mtlo:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_A;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b1;
                ID_Reg_Writed = 3'b101;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
            end
            `break:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                ID_ALUOp = 4'b0;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd={ID_ExceptionType[8:4],1'b1,ID_ExceptionType[2:0]};     //ID_ExceptionTypeEnd.Break=1
            end
            `syscall:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                ID_ALUOp = 4'b0;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd={ID_ExceptionType[8:5],1'b1,ID_ExceptionType[3:0]};     //ID_ExceptionTypeEnd.Syscall=1
            end
            default:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                ID_ALUOp = 4'b0;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd={ID_ExceptionType[8:3],1'b1,ID_ExceptionType[1:0]};     //ID_ExceptionTypeEnd.ReservedInstr=1
            end
            endcase
        end
        `P_type:begin
            unique case(rs)
                `mfc0:begin
                    ID_CP0Wr=1'b0; 
                    ID_DMRd=1'b0;
                    ID_EXTOp = 2'b00;
                    ID_ALUOp = 4'b0;
                      
                    ID_DMWr = 1'b0;
                    ID_ALU_DataA_Sig = 1'b0;
                    ID_ALU_DataB_Sig = 1'b0;
                    ID_Reg_Writed = 3'b010;
                    ID_DMOp = 3'b000;
                    ID_MemToRegWr = 1'b0;
                    ID_Immjump = 1'b0;
                    ID_IsBranch = 1'b0;
                    ID_Data_To_Reg_Sel = 2'b11;
                    ID_ExceptionTypeEnd=ID_ExceptionType;
                end
                `mtc0:begin
                    ID_CP0Wr=1'b1; 
                    ID_DMRd=1'b0;
                    ID_EXTOp = 2'b00;
                    ID_ALUOp = `ALU_B;
                      
                    ID_DMWr = 1'b0;
                    ID_ALU_DataA_Sig = 1'b0;
                    ID_ALU_DataB_Sig = 1'b1;
                    ID_Reg_Writed = 3'b111;
                    ID_DMOp = 3'b000;
                    ID_MemToRegWr = 1'b0;
                    ID_Immjump = 1'b0;
                    ID_IsBranch = 1'b0;
                    ID_Data_To_Reg_Sel = 2'b00;
                    ID_ExceptionTypeEnd=ID_ExceptionType;
                end
                5'b10000:begin
                    unique case(funct)
                        `eret:begin
                            ID_CP0Wr=1'b0; 
                            ID_DMRd=1'b0;
                            ID_EXTOp = 2'b00;
                            ID_ALUOp = 4'b0;
                              
                            ID_DMWr = 1'b0;
                            ID_ALU_DataA_Sig = 1'b0;
                            ID_ALU_DataB_Sig = 1'b0;
                            ID_Reg_Writed = 3'b000;
                            ID_DMOp = 3'b000;
                            ID_MemToRegWr = 1'b0;
                            ID_Immjump = 1'b0;
                            ID_IsBranch = 1'b0;
                            ID_Data_To_Reg_Sel = 2'b00;
                            ID_ExceptionTypeEnd={ID_ExceptionType[8:1],1'b1};     //ID_ExceptionTypeEnd.Eret=1
                        end
                        // `tlbp:begin
                        //     
                        // end
                        // `tlbr:begin
                        //     
                        // end
                        // `tlbwi:begin
                        //     
                        // end
                        default:begin
                            ID_CP0Wr=1'b0; 
                            ID_DMRd=1'b0;
                            ID_EXTOp = 2'b00;
                            ID_ALUOp = 4'b0;
                              
                            ID_DMWr = 1'b0;
                            ID_ALU_DataA_Sig = 1'b0;
                            ID_ALU_DataB_Sig = 1'b0;
                            ID_Reg_Writed = 3'b000;
                            ID_DMOp = 3'b000;
                            ID_MemToRegWr = 1'b0;
                            ID_Immjump = 1'b0;
                            ID_IsBranch = 1'b0;
                            ID_Data_To_Reg_Sel = 2'b00;
                            ID_ExceptionTypeEnd={ID_ExceptionType[8:3],1'b1,ID_ExceptionType[1:0]};     //ID_ExceptionTypeEnd.ReservedInstr=1
                        end
                    endcase
                end
                default:begin
                    ID_CP0Wr=1'b0; 
                    ID_DMRd=1'b0;
                    ID_EXTOp = 2'b00;
                    ID_ALUOp = 4'b0;
                      
                    ID_DMWr = 1'b0;
                    ID_ALU_DataA_Sig = 1'b0;
                    ID_ALU_DataB_Sig = 1'b0;
                    ID_Reg_Writed = 3'b000;
                    ID_DMOp = 3'b000;
                    ID_MemToRegWr = 1'b0;
                    ID_Immjump = 1'b0;
                    ID_IsBranch = 1'b0;
                    ID_Data_To_Reg_Sel = 2'b00;
                    ID_ExceptionTypeEnd={ID_ExceptionType[8:3],1'b1,ID_ExceptionType[1:0]};     //ID_ExceptionTypeEnd.Reserve
                end
            endcase
        end
        `lb:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b1;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = `byte_sign;
                ID_MemToRegWr = 1'b1;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b01;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `lbu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b1;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = `byte_zero;
                ID_MemToRegWr = 1'b1;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b01;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `lh:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b1;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = `half_sign;
                ID_MemToRegWr = 1'b1;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b01;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `lhu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b1;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = `half_zero;
                ID_MemToRegWr = 1'b1;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b01;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `lw:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b1;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = `word;
                ID_MemToRegWr = 1'b1;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b01;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `sb:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b1;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = `byte_sign;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `sh:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b1;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = `half_sign;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `sw:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b1;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = `word;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `addi:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_add;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `addiu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_addu;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `andi:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                 
                ID_ALUOp = `ALU_and;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `ori:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                 
                ID_ALUOp = `ALU_or;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `xori:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                 
                ID_ALUOp = `ALU_xor;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `lui:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b10;
                 
                ID_ALUOp = `ALU_B;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `slti:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_slt;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `sltiu:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                 
                ID_ALUOp = `ALU_sltu;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b1;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b010;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `beq:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b1;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `bne:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b1;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `blez:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;
                  
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b1;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `bgtz:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;     
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b1;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        
        `b_special:begin
            unique case(rt)
            `bltz:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;         
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b1;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
            `bgez:begin
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;            
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b1;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
            `bgezal:begin    
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;       
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b001;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b1;
                ID_Data_To_Reg_Sel = 2'b10;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
            `bltzal:begin    
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b01;
                ID_ALUOp = 4'b0000;       
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b001;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b1;
                ID_Data_To_Reg_Sel = 2'b10;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        default:begin    
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                ID_ALUOp = 4'b0;       
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd={ID_ExceptionType[8:3],1'b1,ID_ExceptionType[1:0]};     //ID_ExceptionTypeEnd.ReservedInstr=1
        end
            endcase
        end

        `j:begin    
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                ID_ALUOp = 4'b0000;       
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b1;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        `jal:begin    
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                ID_ALUOp = 4'b0000;      
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b001;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b1;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b10;
                ID_ExceptionTypeEnd=ID_ExceptionType;
        end
        default:begin    
                ID_CP0Wr=1'b0; 
                ID_DMRd=1'b0;
                ID_EXTOp = 2'b00;
                ID_ALUOp = 4'b0;
                ID_DMWr = 1'b0;
                ID_ALU_DataA_Sig = 1'b0;
                ID_ALU_DataB_Sig = 1'b0;
                ID_Reg_Writed = 3'b000;
                ID_DMOp = 3'b000;
                ID_MemToRegWr = 1'b0;
                ID_Immjump = 1'b0;
                ID_IsBranch = 1'b0;
                ID_Data_To_Reg_Sel = 2'b00;
                ID_ExceptionTypeEnd={ID_ExceptionType[8:3],1'b1,ID_ExceptionType[1:0]};     //ID_ExceptionTypeEnd.ReservedInstr=1
        end
        endcase
    end

endmodule